package com.ebt.m.utils;

import android.util.Log;

import com.google.gson.Gson;

/**
 * Created by Rick.Wang on 2016/12/16.
 */

public class JsonUtil {

    public static final String TAG = "json";

    public static String parseObjectToJson(Object obj){
        if (obj == null){
            return "parseObjectToJson object is null";
        }
        Gson gson = new Gson();
        String ret = gson.toJson(obj);
        return "parseObjectToJson class : " + obj.getClass().getSimpleName() + " content : " + ret;
    }

    public static void parseObjectToJsonWithTag(Object obj){
        if (obj == null){
            Log.d(TAG, "parseObjectToJson object is null");
        }
        Gson gson = new Gson();
        String ret = gson.toJson(obj);
        Log.d(TAG, "parseObjectToJson class : " + obj.getClass().getSimpleName() + " content : " + ret);
    }

    public static void parseObjectToJsonWithTagAndPrefix(String prefix, Object obj){
        if (obj == null){
            Log.d(TAG, "parseObjectToJson object is null");
        }
        Gson gson = new Gson();
        String ret = gson.toJson(obj);
        Log.d(TAG, "" + prefix + " parseObjectToJson class : " + obj.getClass().getSimpleName() + " content : " + ret);
    }
}
